<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2024/4/10
 * Time: 12:01
 */

namespace plugin\admin\app\logic\product;


use plugin\admin\app\logic\BaseLogic;
use plugin\admin\app\model\product\InternalProductModel;
use plugin\admin\app\model\product\VipProductModel;
use plugin\admin\app\model\user\UserRechargeOrderModel;
use support\Request;
use support\Response;

class VipproductLogic extends BaseLogic
{
    protected static $instance;

    public function __construct()
    {
        $this->model = new VipProductModel();
    }

    public static function getInstance()
    {
        //        if(is_object(self::$instance)){
//            return self::$instance;
//        }

        return new self();
    }

    public function select(Request $request): Response
    {
        $field = $request->input('field');
        if($field==false){
            $request->inputSet('field','sort');
            $request->inputSet('order','desc');
        }

        $request->inputSet('isdel','0');
        return parent::select($request);
    }

    public function insert(Request $request): Response
    {
        return parent::insert($request);
    }


    public function update(Request $request): Response
    {
        return parent::update($request);
    }

    protected function doUpdate($id, $data)
    {
        parent::doUpdate($id, $data); // TODO: Change the autogenerated stub
        //把已经订阅的用户每日赠送点数更新
        if(!empty($data['product_id']) && !empty($data['point_nums'])){
            UserRechargeOrderModel::getInstance()->getWhere(['product_id'=>$data['product_id'],'product_type'=>1])->update(['point_nums'=>$data['point_nums']]);
        }
    }

    public function delete(Request $request): Response
    {
        return parent::isDelete($request);
    }
}